﻿using System;
using System.Collections.Generic;
using System.Web.Security;
using VASJ.Model;

namespace VASJ.Provider
{
    public class AcpInetHelperProvider : BaseHelper
    {
        /// <summary>
        /// GetProjectTypesForApplication
        /// </summary>
        /// <param name="UserName"></param>
        /// <returns></returns>
        public List<string> GetProjectTypesForApplication(string UserName)
        {
            return this.GetService().GetProjectTypesForApplication(this._ApplicationName, UserName).ToList();
        }

        /// <summary>
        /// IsUserInProject
        /// </summary>
        /// <param name="username"></param>
        /// <param name="projectid"></param>
        /// <returns></returns>
        public bool IsUserInProject(string username, int projectid)
        {
            return this.GetService().IsUserInProject(this._ApplicationName, username, projectid);
        }

        /// <summary>
        /// GetListUser  
        /// </summary>
        /// <returns></returns>
        public Dictionary<Guid, User> GetListUser()
        {
            return this.GetService().GetListUser(this._ApplicationName );
        }

        /// <summary>
        /// GetListUserInProject
        /// </summary>
        /// <param name="projectid"></param>
        /// <returns></returns>
        public Dictionary<Guid, User> GetListUserInProject(int projectid)
        {
            return this.GetService().GetListUserInProject(this._ApplicationName, projectid);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// Get list user is waiting accept for project
        /// </summary>
        /// <param name="projectid"></param>
        /// <returns></returns>
        public User[] GetWaitingAcceptUserForProject(int projectid)
        {
            return this.GetService().GetWaitingAcceptUserForProject(this._ApplicationName, projectid);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// </summary>
        /// <returns></returns>
        public Dictionary<Guid, User> GetUsersNotInAnyOrgan()
        {
            return this.GetService().GetUsersNotInAnyOrgan(this._ApplicationName);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// </summary>
        /// <returns></returns>
        public User GetUserInfo(string PermitName, string username)
        {
            return this.GetService().GetUserInfo(this._ApplicationName, PermitName, username);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// Check User isExits in the AcpInet, input username is username or email  
        /// </summary>
        /// <returns></returns>
        public bool IsExistUserInAcpInet(string username)
        {
            return this.GetService().IsExistUserInAcpInet(this._ApplicationName, username);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public bool IsExistUser(string username)
        {
            return this.GetService().IsExistUser(this._ApplicationName, username);
        }

        /// <summary>
        /// AddUserToProject
        /// </summary>
        /// <param name="username"></param>
        /// <param name="projectid"></param>
        public void AddUserToProject(string username, int projectid)
        {
            this.GetService().AddUserToProject(this._ApplicationName, username, projectid);
        }

        /// <summary>
        /// InviteUsersToProject
        /// </summary>
        /// <param name="ApplicationName"></param>
        /// <param name="userId"></param>
        /// <param name="projectID"></param>
        /// <returns></returns>
        public int InviteUsersToProject(string[] userId, int projectID)
        {
            return this.GetService().InviteUsersToProject(this._ApplicationName, userId, projectID);
        }

        /// <summary>
        /// AcceptInvitedUserToProject
        /// </summary>
        /// <param name="ApplicationName"></param>
        /// <param name="userId"></param>
        /// <param name="projectId"></param>
        /// <param name="isAccept"></param>
        /// <returns></returns>
        public int AcceptInvitedUserToProject(string userId, int projectId, bool isAccept)
        {
            return this.GetService().AcceptInvitedUserToProject(this._ApplicationName, userId, projectId, isAccept);
        }

        /// <summary>
        /// AddUserToProjectIncludeRole
        /// </summary>
        /// <param name="username"></param>
        /// <param name="projectid"></param>
        public bool AddUserToProject(string username, int projectid, string roleName)
        {
            return this.GetService().AddUserToProjectIncludeRole(this._ApplicationName, username, projectid, roleName);
        }

        /// <summary>
        /// CreateProjectType
        /// </summary>
        public void CreateProjectType()
        {
            this.GetService().CreateProjectType(this._ApplicationName);
        }

        /// <summary>
        /// CreateRoleForProjectType
        /// </summary>
        public void CreateRoleForProjectType()
        {
            this.GetService().CreateRoleForProjectType(this._ApplicationName);
        }

        /// <summary>
        /// GetOrganization
        /// </summary>
        /// <returns></returns>
        public Dictionary<Guid, Organization> GetOrganization()
        {
            return this.GetService().GetOrganization(this._ApplicationName);
        }

        /// <summary>
        /// Get Organization by PrimaryKey
        /// </summary>
        /// <param name="OrgId"></param>
        /// <param name="msgError"></param>
        /// <returns></returns>
        public Organization GetOrganizationById(string OrgId, ref string msgError)
        {
            return this.GetService().GetOrganizationById(this._ApplicationName, OrgId, ref msgError);
        }

        /// <summary>
        /// GetUserInOrganization
        /// </summary>
        /// <param name="OrgID"></param>
        /// <returns></returns>
        public Dictionary<Guid, MembershipUser> GetUserInOrganization(Guid OrgID)
        {
            return this.GetService().GetUserInOrganization(this._ApplicationName, OrgID);
        }

        /// <summary>
        /// AddUserToOrgs
        /// </summary>
        /// <param name="UserID"></param>
        /// <param name="idOrgs"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public bool AddUserToOrgs(Guid UserID, string[] idOrgs, ref string msg)
        {
            return this.GetService().AddUserToOrgs(this._ApplicationName, UserID, idOrgs, ref msg);
        }

        /// <summary>
        /// AddUserToProjects
        /// </summary>
        /// <param name="UserID"></param>
        /// <param name="idProjs"></param>
        /// <returns></returns>
        public bool AddUserToProjects(Guid UserID, string[] idProjs)
        {
            return this.GetService().AddUserToProjects(this._ApplicationName, UserID, idProjs);
        }

        /// <summary>
        /// RemoveUserFromProjects
        /// </summary>
        /// <param name="UserID"></param>
        /// <returns></returns>
        public bool RemoveUserFromProjects(Guid UserID)
        {
            return this.GetService().RemoveUserFromProjects(this._ApplicationName, UserID);
        }

        /// <summary>
        /// RemoveUserFromProject
        /// </summary>
        /// <param name="projectId"></param>
        /// <param name="username"></param>
        /// <param name="rolename"></param>
        /// <returns></returns>
        public bool RemoveUserFromProject(int projectId, string username, string rolename = null)
        {
            return this.GetService().RemoveUserFromProject(this._ApplicationName, projectId, username, rolename);
        }

        /// <summary>
        /// RemoveUserFromOrgs
        /// </summary>
        /// <param name="UserID"></param>
        /// <returns></returns>
        public bool RemoveUserFromOrgs(Guid UserID)
        {
            return this.GetService().RemoveUserFromOrgs(this._ApplicationName, UserID);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// </summary>
        /// <returns></returns>
        public bool RemoveUserFromProjectsForCS(Guid UserID, Int32[] idPrjDels, ref string message)
        {
            return this.GetService().RemoveUserFromProjectsForApplication(this._ApplicationName, UserID, idPrjDels, ref message);
        }
        
        /// <summary>
        /// Author: Hoang Van Tai
        /// </summary>
        /// <returns></returns>
        public bool RemoveUserFromOrgsForCS(Guid UserID, string[] idOrgDels, ref string message)
        {
            return this.GetService().RemoveUserFromOrgsForApplication(this._ApplicationName, UserID, idOrgDels, ref message);
        }
        
        /// <summary>
        /// DeleteProject
        /// </summary>
        /// <param name="ProjectID"></param>
        /// <returns></returns>
        public bool DeleteProject(int ProjectID)
        {
            return this.GetService().DeleteProject(this._ApplicationName, ProjectID);
        }
        
        /// <summary>
        /// GetRolesForUser
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public Dictionary<Guid, Role> GetRolesForUser(string username)
        {
            return this.GetService().GetRolesForUser2(this._ApplicationName, username);
        }

        /// <summary>
        /// GetRolesForUserInProject
        /// </summary>
        /// <param name="projectId"></param>
        /// <param name="username"></param>
        /// <returns></returns>
        public string[] GetRolesForUserInProject(int projectId, string username)
        {
            return this.GetService().GetRolesForUserInProject(this._ApplicationName, projectId, username);
        }

        /// <summary>
        /// AddOrganization
        /// </summary>
        /// <param name="name"></param>
        /// <param name="description"></param>
        /// <param name="idUsers"></param>
        /// <param name="idPrjRoles"></param>
        /// <param name="OwnerID"></param>
        /// <returns></returns>
        public bool AddOrganization(string name, string description, string[] idUsers, string[] idPrjRoles, Guid OwnerID)
        {
            return this.GetService().AddOrganization(this._ApplicationName, name, description, idUsers, idPrjRoles, OwnerID);
        }

        /// <summary>
        /// UpdateOrganization
        /// </summary>
        /// <param name="OrgID"></param>
        /// <param name="name"></param>
        /// <param name="description"></param>
        /// <param name="idUsers"></param>
        /// <param name="idPrjRoles"></param>
        /// <returns></returns>
        public bool UpdateOrganization(Guid OrgID, string name, string description, string[] idUsers, string[] idPrjRoles)
        {
            return this.GetService().UpdateOrganization(this._ApplicationName, OrgID, name, description, idUsers, idPrjRoles);
        }

        /// <summary>
        /// UpdateOrganization
        /// </summary>
        /// <param name="OrgID"></param>
        /// <param name="name"></param>
        /// <param name="description"></param>
        /// <param name="idUsers"></param>
        /// <returns></returns>
        public bool UpdateOrganization(Guid OrgID, string name, string description, string[] idUsers)
        {
            return this.GetService().UpdateOrganizationNotProject(this._ApplicationName, OrgID, name, description, idUsers);
        }

        /// <summary>
        /// DeleteOrganization
        /// </summary>
        /// <param name="OrgID"></param>
        /// <returns></returns>
        public bool DeleteOrganization(Guid OrgID)
        {
            return this.GetService().DeleteOrganization(this._ApplicationName, OrgID);
        }

        /// <summary>
        /// RemoveOrgsFromProject
        /// </summary>
        /// <param name="ProjectID"></param>
        /// <returns></returns>
        public bool RemoveOrgsFromProject(int ProjectID)
        {
            return this.GetService().RemoveOrgsFromProject(this._ApplicationName, ProjectID);
        }
        
        /// <summary>
        /// DeleteMainProject
        /// </summary>
        /// <param name="ProjectID"></param>
        /// <returns></returns>
        public bool DeleteMainProject(int ProjectID)
        {
            return this.GetService().DeleteProject(this._ApplicationName, ProjectID);
        }

        /// <summary>
        /// AddOrgsToProject
        /// </summary>
        /// <param name="ProjectID"></param>
        /// <param name="idOrgs"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public bool AddOrgsToProject(int ProjectID, string[] idOrgs, ref string message)
        {
            bool retVal = this.GetService().AddOrgsToProject(this._ApplicationName, ProjectID, idOrgs);
            if (retVal) message = "Success!"; else message = "Fail!";
            return retVal;
        }

        /// <summary>
        /// AddProject
        /// </summary>
        /// <param name="name"></param>
        /// <param name="description"></param>
        /// <param name="idUserRoles"></param>
        /// <param name="idOrgRoles"></param>
        /// <returns></returns>
        public int AddProject(string name, string description, string owner, string[] idUserRoles, string[] idOrgRoles)
        {
            return this.GetService().AddProject(this._ApplicationName, name, description, owner, idUserRoles, idOrgRoles);
        }

        /// <summary>
        /// UpdateProject
        /// </summary>
        /// <param name="mainPrjId"></param>
        /// <param name="name"></param>
        /// <param name="description"></param>
        /// <param name="idUserRoles"></param>
        /// <param name="idOrgRoles"></param>
        /// <returns></returns>
        public int UpdateProject(int mainPrjId, string name, string description, string owner, string[] idUserRoles, string[] idOrgRoles)
        {
            return this.GetService().UpdateProject(this._ApplicationName, mainPrjId, name, description, owner, idUserRoles, idOrgRoles);
        }

        /// <summary>
        /// GetOrganizationForProject
        /// </summary>
        /// <param name="projectID"></param>
        /// <returns></returns>
        public Dictionary<Guid, Organization> GetOrganizationForProject(int projectID)
        {
            return this.GetService().GetOrganizationForProject(this._ApplicationName, projectID);
        }

        /// <summary>
        /// GetOrganizationForProject
        /// </summary>
        /// <param name="projectID"></param>
        /// <param name="rolename"></param>
        /// <returns></returns>
        public Organization[] GetOrganizationForProject(int projectID, string rolename)
        {
            return this.GetService().GetOrganizationsForProject(this._ApplicationName, projectID, rolename);
        }

        /// <summary>
        /// GetOrganizationForUser
        /// </summary>
        /// <param name="userID"></param>
        /// <returns></returns>
        public Dictionary<Guid, Organization> GetOrganizationForUser(Guid userID)
        {
            return this.GetService().GetOrganizationForUser(this._ApplicationName, userID);
        }

        /// <summary>
        /// Send request forgot password
        /// </summary>
        /// <param name="ApplicationName"></param>
        /// <param name="userName"></param>
        /// <returns></returns>
        public bool SendRequestForgotPassword(string userName, string linkReset)
        {
            return this.GetService().SendRequestForgotPassword(this._ApplicationName, userName, linkReset);
        }

        /// <summary>
        /// Check forgot code is existing
        /// </summary>
        /// <param name="ApplicationName"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        public bool IsExistForgotCode(string code)
        {
            return this.GetService().IsExistForgotCode(this._ApplicationName, code);
        }

        /// <summary>
        /// Change pass by code
        /// </summary>
        /// <param name="code"></param>
        /// <param name="passWord"></param>
        /// <returns></returns>
        public bool ChangePassByCode(string code, string passWord)
        {
            return this.GetService().ChangePassByCode(this._ApplicationName, code, passWord);
        }

        /// <summary>
        /// Add role for project type
        /// </summary>
        /// <param name="ProjectTypeName"></param>
        /// <param name="RoleName"></param>
        /// <returns></returns>
        public bool AddRoleForProjectType(string ProjectTypeName, string RoleName, string RoleDisplay, int? Priority = null)
        {
            return this.GetService().AddRoleForProjectType(this._ApplicationName, ProjectTypeName, RoleName, RoleDisplay, Priority);
        }

        /// <summary>
        /// Get all role for project type
        /// </summary>
        /// <param name="ProjectTypeName"></param>
        /// <returns></returns>
        public string[] GetAllRolesForProjectType(string ProjectTypeName)
        {
            return this.GetService().GetAllRolesForProjectType(this._ApplicationName, ProjectTypeName);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// Check Role of User in project 
        /// </summary>
        /// <returns></returns>
        public bool IsRoleOfUserInProject(int projectId, string username, string roleName)
        {
            return this.GetService().IsRoleOfUserInProject(this._ApplicationName, projectId, username, roleName);
        }

        /// <summary>
        /// Send mail
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="email"></param>
        /// <param name="subject"></param>
        /// <param name="body"></param>
        /// <returns></returns>
        public bool SendMail(string userName, string email, string subject, string body)
        {
            return this.GetService().SendMail(this._ApplicationName, userName, email, subject, body);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// Get list role for ispm and prjtype
        /// </summary>
        /// <param name="ispm"></param>
        /// <param name="prjtype"></param>
        /// <returns></returns>
        public Role[] GetRoleList(string username, bool ispm = false, int prjtype = 0)
        {
            return this.GetService().GetRoleList(this._ApplicationName, username, ispm, prjtype);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// Get list role
        /// </summary>
        /// <returns></returns>
        public Role[] GetAllRole()
        {
            return this.GetService().GetAllRole(this._ApplicationName);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// Change status organization in project
        /// </summary>
        /// <param name="orgID"></param>
        /// <param name="prjID"></param>
        /// <param name="status"></param>
        /// <param name="msgError"></param>
        /// <returns></returns>
        public int ChangeStatusOrganInProject(Guid orgID, int prjID, int status, ref string msgError)
        {
            return this.GetService().ChangeStatusOrganInProject(this._ApplicationName, orgID, prjID, status, ref msgError);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// Search Organization by SA
        /// </summary>
        /// <param name="OrgId"></param>
        /// <param name="msgError"></param>
        /// <returns></returns>
        public Organization[] SearchOrganizationSA(string OrgId, ref string msgError)
        {
            return this.GetService().SearchOrganizationSA(this._ApplicationName, OrgId, ref msgError);
        }

        /// <summary>
        /// Get List Org from user
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="msgError"></param>
        /// <returns></returns>
        public Organization[] GetOrgsListFromUser(string userId, ref string msgError)
        {
            return this.GetService().GetOrgsListFromUser(this._ApplicationName, userId, ref msgError);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// Get list organization not orgName
        /// </summary>
        /// <param name="orgName"></param>
        /// <param name="msgError"></param>
        /// <returns></returns>
        public Organization[] GetOrganizationsListNotOrgName(string orgName, ref string msgError)
        {
            return this.GetService().GetOrganizationsListNotOrgName(this._ApplicationName, orgName, ref msgError);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// Add Organization
        /// </summary>
        /// <param name="name"></param>
        /// <param name="description"></param>
        /// <param name="organtype"></param>
        /// <param name="orgrole"></param>
        /// <param name="ownerid"></param>
        /// <param name="ownertype"></param>
        /// <param name="userInvite"></param>
        /// <param name="projecttype"></param>
        /// <param name="userNames"></param>
        /// <param name="idPrjRoles"></param>
        /// <param name="userRoles"></param>
        /// <param name="msgError"></param>
        /// <returns></returns>
        public Guid? AddOrganization(string name, string description, string organtype, string orgrole, string ownerid, string ownertype, string userInvite, string projecttype, string[] userNames, string[] idPrjRoles, string[] userRoles, ref string msgError)
        {
            return this.GetService().AddOrganizationPropertiesAll(this._ApplicationName, name, description, organtype, orgrole, ownerid, ownertype, userInvite, projecttype, userNames, idPrjRoles, userRoles, ref msgError);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// Update Organization
        /// </summary>
        /// <param name="orgId"></param>
        /// <param name="name"></param>
        /// <param name="description"></param>
        /// <param name="organtype"></param>
        /// <param name="orgrole"></param>
        /// <param name="ownerid"></param>
        /// <param name="ownertype"></param>
        /// <param name="userInvite"></param>
        /// <param name="projecttype"></param>
        /// <param name="idUsers"></param>
        /// <param name="idPrjRoles"></param>
        /// <param name="msgError"></param>
        /// <returns></returns>
        public int UpdateOrganization(string orgId, string name, string description, string organtype, string orgrole, string ownerid, string ownertype, string userInvite, string projecttype, string[] idUsers, string[] idPrjRoles, ref string msgError)
        {
            return this.GetService().UpdateOrganizationPropertiesAll(this._ApplicationName, orgId, name, description, organtype, orgrole, ownerid, ownertype, userInvite, projecttype, idUsers,  idPrjRoles, ref msgError);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// Assign user to Org
        /// </summary>
        /// <param name="orgId"></param>
        /// <param name="username"></param>
        /// <param name="userNames"></param>
        /// <param name="msgError"></param>
        /// <returns></returns>
        public int AssignUsersToOrg(Guid orgId, string username, string[] userNames, ref string msgError)
        {
            return this.GetService().AssignUsersToOrg(this._ApplicationName, orgId, username, userNames, ref msgError);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// Add user to Org
        /// </summary>
        /// <param name="orgId"></param>
        /// <param name="userInvite"></param>
        /// <param name="userNames"></param>
        /// <param name="msgError"></param>
        /// <returns></returns>
        public int AddUsersToOrg(Guid orgId, string userInvite, string[] userNames, ref string msgError)
        {
            return this.GetService().AddUsersToOrg(this._ApplicationName, orgId, userInvite, userNames, ref msgError);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// Save user and Role to Org
        /// </summary>
        /// <param name="orgId"></param>
        /// <param name="userInvite"></param>
        /// <param name="userRoles"></param>
        /// <param name="msgError"></param>
        /// <returns></returns>
        public int SaveUsersRoleToOrg(Guid orgId, string userInvite, string[] userRoles, ref string msgError)
        {
            return this.GetService().SaveUsersRoleToOrg(this._ApplicationName, orgId, userInvite,  userRoles, ref msgError);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// Save Org and Role to Prj
        /// </summary>
        /// <param name="orgId"></param>
        /// <param name="userInvite"></param>
        /// <param name="prjRoles"></param>
        /// <param name="msgError"></param>
        /// <returns></returns>
        public int SaveOrgsRoleToPrj(Guid orgId, string userInvite, string[] prjRoles, ref string msgError)
        {
            return this.GetService().SaveOrgsRoleToPrj(this._ApplicationName, orgId, userInvite, prjRoles, ref msgError);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// Remove user from Org
        /// </summary>
        /// <param name="idUserDels"></param>
        /// <param name="orgId"></param>
        /// <param name="msgError"></param>
        /// <returns></returns>
        public int RemoveUsersFromOrg(string[] idUserDels, Guid orgId, ref string msgError)
        {
            return this.GetService().RemoveUsersFromOrg(this._ApplicationName, idUserDels, orgId, ref msgError);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// Remove project from Org
        /// </summary>
        /// <param name="idPrjDels"></param>
        /// <param name="orgId"></param>
        /// <returns></returns>
        public int RemoveProjectsFromOrg(string[] idPrjDels, Guid orgId)
        {
            return this.GetService().RemoveProjectsFromOrg(this._ApplicationName, idPrjDels, orgId);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// Save Prj and Role to Org
        /// </summary>
        /// <param name="orgId"></param>
        /// <param name="userInvite"></param>
        /// <param name="idPrjDels"></param>
        /// <param name="PrjRoles"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public int SavePrjsRoleToOrg(string orgId, string userInvite, string[] idPrjDels, string[] PrjRoles, ref string message)
        {
            return this.GetService().SavePrjsRoleToOrg(this._ApplicationName, orgId, userInvite, idPrjDels, PrjRoles, ref message);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// Get list Organization by SA
        /// </summary>
        /// <param name="ApplicationName"></param>
        /// <param name="msgError"></param>
        /// <returns></returns>
        public Organization[] GetOrganizationsListBySA(ref string msgError)
        {
            return this.GetService().GetOrganizationsListBySA(this._ApplicationName, ref msgError);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// Get list Organization and User is owner
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public Organization[] GetOwnersList(string user)
        {
            return this.GetService().GetOwnersList(this._ApplicationName, user);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// Add Org to User
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="userInviteID"></param>
        /// <param name="idOrgs"></param>
        /// <param name="msgError"></param>
        /// <returns></returns>
        public int AddOrgsToUser(Guid userId, string userInviteID, string[] idOrgs, ref string msgError)
        {
            return this.GetService().AddOrgsToUser(this._ApplicationName, userId, userInviteID, idOrgs, ref msgError);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// Insert invite Email Org
        /// </summary>
        /// <param name="emails"></param>
        /// <param name="OrgId"></param>
        /// <param name="RoleId"></param>
        /// <returns></returns>
        public string InsertInviteEmailOrg(string emails, Guid OrgId, Guid? RoleId)
        {
            return this.GetService().InsertInviteEmailOrg(this._ApplicationName, emails, OrgId, RoleId);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// Insert invite
        /// </summary>
        /// <param name="ApplicationName"></param>
        /// <param name="emails"></param>
        /// <param name="RoleId"></param>
        /// <param name="OwnerID"></param>
        /// <returns></returns>
        public string InsertInvite(string emails, Guid? RoleId, Guid? OwnerID)
        {
            return this.GetService().InsertInvite(this._ApplicationName, emails, RoleId, OwnerID);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// Get list user from Org
        /// </summary>
        /// <param name="orgId"></param>
        /// <param name="msgError"></param>
        /// <returns></returns>
        public User[] GetUsersListFromOrg(string orgId, ref string msgError)
        {
            return this.GetService().GetUsersListFromOrg(this._ApplicationName, orgId, ref msgError);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// Set Approved
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="isApproved"></param>
        /// <param name="msgError"></param>
        /// <returns></returns>
        public int SetApproved(Guid userId, bool isApproved, ref string msgError)
        {
            return this.GetService().SetApproved(this._ApplicationName, userId, isApproved, ref msgError);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// Get user owner for userId
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="msgError"></param>
        /// <returns></returns>
        public User GetUserOwnerByPrimaryKey( string userId, ref string msgError)
        {
            return this.GetService().GetUserOwnerByPrimaryKey(this._ApplicationName, userId, ref msgError);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// Action Invite Organization for userId 
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="orgId"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public bool ActionInviteOrganizationsList(string userId, string orgId, int status)
        {
            return this.GetService().ActionInviteOrganizationsList(this._ApplicationName, userId, orgId, status);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// Action Invite list project for userId
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="prjId"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public bool ActionInviteProjectsList( string userId, int prjId, int status)
        {
            return this.GetService().ActionInviteProjectsList(this._ApplicationName, userId, prjId, status);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// Search user by SA
        /// </summary>
        /// <param name="keyword"></param>
        /// <param name="msgError"></param>
        /// <returns></returns>
        public User[] SearchUserSA( string keyword, ref string msgError)
        {
            return this.GetService().SearchUserSA(this._ApplicationName, keyword, ref msgError);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// Get list user IsApproved or IsLockedOut
        /// </summary>
        /// <returns></returns>
        public User[] GetListUserSA()
        {
            return this.GetService().GetListUserSA(this._ApplicationName);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// Update Prj and Role
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="idPrjRoles"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public int UpdatePrjAndRole(Guid userId, string[] idPrjRoles, ref string message)
        {
            return this.GetService().UpdatePrjAndRole(this._ApplicationName, userId, idPrjRoles, ref message);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// Add user
        /// </summary>
        /// <param name="user"></param>
        /// <param name="username"></param>
        /// <param name="name"></param>
        /// <param name="email"></param>
        /// <param name="phone"></param>
        /// <param name="password"></param>
        /// <param name="ownerid"></param>
        /// <param name="isApproved"></param>
        /// <param name="isSendEmail"></param>
        /// <param name="idOrgs"></param>
        /// <param name="idPrjRoles"></param>
        /// <param name="msgError"></param>
        /// <returns></returns>
        public Guid? AddUser(string user, string username, string name, string email, string phone, string password, string ownerid, string isApproved, string isSendEmail, string[] idOrgs, string[] idPrjRoles, ref string msgError)
        {
            return this.GetService().AddUser(this._ApplicationName, user, username, name, email, phone, password, ownerid, isApproved, isSendEmail, idOrgs, idPrjRoles, ref msgError);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// Update user
        /// </summary>
        /// <param name="user"></param>
        /// <param name="userId"></param>
        /// <param name="name"></param>
        /// <param name="phone"></param>
        /// <param name="password"></param>
        /// <param name="email"></param>
        /// <param name="ownerid"></param>
        /// <param name="isApproved"></param>
        /// <param name="idOrgs"></param>
        /// <param name="idOrgDels"></param>
        /// <param name="idPrjRoles"></param>
        /// <param name="msgError"></param>
        /// <returns></returns>
        public int UpdateUser(string user, string userId, string name, string phone, string password, string email, string ownerid, string isApproved, string[] idOrgs, string[] idOrgDels, string[] idPrjRoles, ref string msgError)
        {
            return this.GetService().UpdateUserProperiesAll(this._ApplicationName, user, userId, name, phone, password, email, ownerid, isApproved,  idOrgs,  idOrgDels,  idPrjRoles, ref msgError);
        }

        /// <summary>
        /// Remove Org from user
        /// </summary>
        /// <param name="idOrgDels"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public int RemoveOrgsFromUser(string[] idOrgDels, Guid userId)
        {
            return this.GetService().RemoveOrgsFromUser(this._ApplicationName, idOrgDels, userId);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// add user to project
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="userInviteID"></param>
        /// <param name="idPrjRoles"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public int AddUserToProjects(Guid userId, string userInviteID, string[] idPrjRoles, ref string message)
        {
            return this.GetService().AddUserToProjectsWithInvite(this._ApplicationName, userId, userInviteID, idPrjRoles, ref message);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// Get list user for project
        /// </summary>
        /// <param name="ApplicationName"></param>
        /// <param name="projetcId"></param>
        /// <returns></returns>
        public User[] GetUsersForProject(int projetcId)
        {
            return this.GetService().GetUsersForProject(this._ApplicationName, projetcId);
        }


        /// <summary>
        /// Author: Hoang Van Tai
        /// Set Org be Owner user
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="orgId"></param>
        /// <param name="msgError"></param>
        /// <returns></returns>
        public int SetOrganBeOwnerUser(Guid userid, Guid orgId, ref string msgError)
        {
            return this.GetService().SetOrganBeOwnerUser(this._ApplicationName, userid, orgId, ref msgError);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// Set Org be owner user and Assign user to Org
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="orgId"></param>
        /// <param name="msgError"></param>
        /// <returns></returns>
        public int SetOrganBeOwnerUserAndAssignUserToOrg(Guid userid, Guid orgId, ref string msgError)
        {
            return this.GetService().SetOrganBeOwnerUserAndAssignUserToOrg(this._ApplicationName, userid, orgId, ref msgError);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// Remove request be owner
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="msgError"></param>
        /// <returns></returns>
        public int RemoveRequestBeOwner(int Id, ref string msgError)
        {
            return this.GetService().RemoveRequestBeOwner(this._ApplicationName, Id, ref msgError);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// Add user in application
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        public bool AddUserToApplication(string userName)
        {
            return this.GetService().AddUserToApplication(this._ApplicationName, userName);
        }

        /// <summary>
        /// Author: Hoang Van Tai
        /// Tạo Service đồng bộ người dùng trong Application
        /// </summary>
        /// <param name="ApplicationName"></param>
        /// <returns></returns>
        public bool SynServiceUserToApplication()
        {
            return this.GetService().SynServiceUserToApplication(this._ApplicationName);
        }        
    }
}